#include "configer.h"

Configer::Configer()
{

}

bool Configer::readCfg(QString filepath, QJsonArray *jsonInfro, QJsonObject *jsonInfor)
{
    QString strJson;
    QJsonParseError jsonError;
    // BaseLib mBaseLib;

    QFile *file = new QFile(filepath);
    if (file->open(QIODevice::ReadOnly | QIODevice::Text))
    {
        strJson = file->readAll();
        // qWarning()<<strJson;
        file->close();
    }
    else
    {
        return false;
    }
    file->close();

    QJsonDocument jsonDom = QJsonDocument::fromJson(strJson.toUtf8(), &jsonError);
    QJsonObject jsonObject = jsonDom.object();
    QJsonArray jsonArray = jsonObject.value("UDS").toArray();

    if(jsonDom.isNull() != true)
    {
        *jsonInfro = jsonArray;
        *jsonInfor = jsonObject.value("TP").toObject();

        u8ReadSuccFlag = true;
    }
    else
    {
        u8ReadSuccFlag = false;
    }

    return u8ReadSuccFlag;
}
